<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数对和</title>
</head>
<body>
  <script>
    function fn(nums, target) {
      let res = [], map = new Map(), len = nums.length;
      for (let i = 0; i < len; i++) {
        let cur = nums[i], pre = target - cur;
        if (map.has(pre) && map.get(pre) > 0) {
          map.set(pre, map.get(pre) - 1)
          res.push([pre, cur])
        } else {
          map.set(cur, map.has(cur) ? map.get(cur) + 1 : 1)
        }
      }
      return res
    }
    console.log(fn([5, 6, 5], 11))
  </script>
</body>
</html>